<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/context.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta http-equiv="pragma" content="no-cache"> 
<meta http-equiv="cache-control" content="no-cache"> 
<meta http-equiv="expires" content="0"> 
<title>创建自主采购信息</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="<%=path%>/common/script/context.js" type="text/javascript"></script>
<script src="<%=path%>/common/script/context_from.js" type="text/javascript"></script>
<!-- 上传组件引入js -->
<link href="<%= path %>/common/swfupload/process.css" rel="stylesheet" type="text/css"/>
<script src="<%= path %>/common/swfupload/swfupload.js" type="text/javascript"></script>
<script src="<%= path %>/common/swfupload/swfupload.queue.js" type="text/javascript"></script>
<script src="<%= path %>/common/swfupload/fileprogress.js" type="text/javascript"></script>
<script src="<%= path %>/common/swfupload/handlers.js" type="text/javascript"></script>
<script src="<%= path %>/common/swfupload/file.js" type="text/javascript"></script>
<script src="<%= path %>/common/script/required/requirePlan.js" type="text/javascript" ></script>
<script language="javaScript">
//附件需要添加的信息
var sessionId="<%=session.getId()%>";
var attachmentType="RequiredCollect"; //当前是哪个类别功能上传的附件
var path="<%= path %>" 
 var fileNameData=${requiredCollect.fileNameData};
 var uuIdData=${requiredCollect.uuIdData};
 var fileTypeData=${requiredCollect.fileTypeData};
 var attIdData=${requiredCollect.attIdData};
 
var num = <c:out value="${fn:length(listValue)}"/>;
var map = {};
function addRow(buyCode,buyName,materialType,unit,amount,deliverDate,rmdId){
	
	tr=document.getElementById("listtable").insertRow();
    tr.className="input_ys1";
    var cell1 = tr.insertCell(); 
    var cell2 = tr.insertCell();
	var cell3 = tr.insertCell();
	var cell4 = tr.insertCell();
	var cell5 = tr.insertCell();
	var cell6 = tr.insertCell();
	var cell7 = tr.insertCell();
	var cell8 = tr.insertCell();
	cell1.innerHTML="<input type='hidden' name='rcdList["+num+"].rmdId' value='"+rmdId+"'/>"
		    +"<button class='btn btn-mini btn-danger' type='button' onclick='deleteRow(this,"+rmdId+")'><i class=\"icon-white icon-trash\"></i></button>";
	cell2.innerHTML=buyCode+"<input name='rcdList["+num+"].buyCode' type='hidden' value='"+buyCode+"'/>" ;
	cell3.innerHTML=buyName+"<input name='rcdList["+num+"].buyName' type='hidden' value='"+buyName+"'/>" ;
	cell4.innerHTML=materialType+"<input name='rcdList["+num+"].materialType' type='hidden' value='"+materialType+"'/>" ;
	cell5.innerHTML=unit+"<input name='rcdList["+num+"].unit' type='hidden' value='"+unit+"'/>" ;
	cell6.innerHTML="<input type='text' name='rcdList["+num+"].amount'  id='amount' value='"+amount+"' size='5' style='width: 55px' onblur='checkAmount("+amount+",this)'>";
	cell7.innerHTML=deliverDate+"<input name='rcdList["+num+"].deliverDate' type='hidden' value='"+deliverDate+"'/>" ;
	cell8.innerHTML="<input name='rcdList["+num+"].remark' type='text' style='width: 90%'/>" ;
	num++;
}
	//删除一行
	function deleteRow(obj,rmdId){
	    delete map[rmdId];  
		$(obj).parent().parent().remove(); 
	}
	
	var acd;
	//选择采购对象
	function selectRequiredPlan(){
		var url="viewNotCollectedRequiredPlan_purchaseBase.action";		
		createdetailwindow("选择未汇总的计划",url,3);
	}
   //选择采购对象
   function doReturn(){	
	   var winObj=document.getElementById('returnVals').value;
		if(winObj){
			var returnVals = winObj.split('@');
			var rmSource = returnVals[0];
			for(var i=1;i<returnVals.length;i++){
				var buyCode = returnVals[i].split("#")[0];
				var buyName = returnVals[i].split("#")[1];
				var materialType = returnVals[i].split("#")[2];
				var unit = returnVals[i].split("#")[3];
				var amount = returnVals[i].split("#")[4];
				var deliverDate = returnVals[i].split("#")[5];
				var rmdId = returnVals[i].split("#")[6];
			    
			    if(!map.hasOwnProperty(rmdId)){
			      map[rmdId]=rmdId;
				  addRow(buyCode,buyName,materialType,unit,amount,deliverDate,rmdId);
				}
				
			}
		}	
     }
   function checkAmount(amount,obj){
	  var newAmount = obj.value;
	    if(newAmount==""){
	        showMsg("alert","采购数量不能为空!")
			obj.value=amount;
			return false;
	    }
		if(isNaN(newAmount)){
			showMsg("alert","请输入数字!");
			obj.value=amount;
			return false;
		}else{
			var index=newAmount.indexOf(".");
			if(index!=-1){
				var b = newAmount.charAt(index+3);
				if(b!=""){
					showMsg("alert","小数点要最多两位，请更正！");
			obj.value=amount;			
					return false;
				}  
			}
		 }
		 if(parseFloat(newAmount)>parseFloat(amount)){
	            showMsg("alert","本次采购数量不能大于剩余数量“"+amount+"”，请更正！");
			    obj.value=amount;			
				return false;
		 }
   }
</script>
</head>
<body >
<div class="container-fluid">
<div class="row-fluid">
<div class="span12" id="content">
<form class="defaultForm" id="cx" method="post" action="saveRequiredCollect_purchaseself.action">
<input type="hidden" id="rcId" name="requiredCollect.rcId" value="${requiredCollect.rcId }"/>
<input type="hidden" id="bidCode" name="requiredCollect.bidCode" value="${requiredCollect.bidCode }"/>
<input type="hidden" name="requiredCollect.floatCode" value="${requiredCollect.floatCode }"/>
<input type="hidden" name="requiredCollect.buyWay" value="${requiredCollect.buyWay }"/>
<input type="hidden" name="requiredCollect.supplierType" value="${requiredCollect.supplierType= }"/>
<input type="hidden" name="requiredCollect.status" value="${requiredCollect.status }"/>
<input type="hidden" name="requiredCollect.serviceStatus" value="${requiredCollect.serviceStatus }"/>
<input type="hidden" name="requiredCollect.serviceStatusCn" value="${requiredCollect.serviceStatusCn }"/>
<input type="hidden" name="requiredCollect.bidStatus" value="${requiredCollect.bidStatus }"/>
<input type="hidden" name="requiredCollect.bidStatusCn" value="${requiredCollect.bidStatusCn }"/>
<input type="hidden" name="requiredCollect.isSendNotice" value="${requiredCollect.isSendNotice }"/>
<input type="hidden" name="requiredCollect.comId" value="${requiredCollect.comId }"/>

<input type="hidden" name="requiredCollect.attIds" id="attIds" />
<input type="hidden" name="requiredCollect.fileNameData" id="fileNameData" value="${requiredCollect.fileNameData }"/>
<input type="hidden" name="requiredCollect.uuIdData" id="uuIdData" value="${requiredCollect.uuIdData }"/>
<input type="hidden" name="requiredCollect.fileTypeData" id="fileTypeData" value="${requiredCollect.fileTypeData }"/>
<input type="hidden" name="requiredCollect.attIdData" id="attIdData" value="${requiredCollect.attIdData }"/>
<input type="hidden" name="returnVals" id="returnVals" value=""/>
<!-- 防止表单重复提交 -->
<s:token/>	
	<table align="center" class="table_ys1" style="margin-top:5px;">
		<tr align="center" class="Content_tab_style_05"><th colspan="4">编辑自主采购</th></tr>
		<tr >
			 <td width="15%" class="Content_tab_style1">项目名称：</td>
			 <td width="35%" align="left">
			 	<input type="text" id="buyRemark" datatype="*6-100" nullmsg="项目名称不能为空！" errormsg="项目名称必须在6-50字之内！" name="requiredCollect.buyRemark" value="${requiredCollect.buyRemark }" size="70"/>
			 	<font color="#FF0000">*</font>
			 	<div class="info"><span class="Validform_checktip">项目名称必须在6-50字之内！</span><span class="dec"><s class="dec1">&#9670;</s><s class="dec2">&#9670;</s></span></div>
			</td>
			<td width="15%" class="Content_tab_style1">项目编号：</td>
			 <td width="35%" align="left">
			 	${requiredCollect.bidCode }				
			 </td>
		</tr>
		<tr>
			<td class="Content_tab_style1" nowrap>采购组织：</td>
			<td class="Content_tab_style2">
				${purchaseDeptName }
				<input type="hidden" name="requiredCollect.purchaseDeptId" value="${requiredCollect.purchaseDeptId }"/>
			</td>
			<td class="Content_tab_style1">负责人：</td>
			<td class="Content_tab_style2">
				${writerCn }
 				<input type="hidden" id="writer" name="requiredCollect.writer" value="${requiredCollect.writer }"/>
			</td>
		</tr>
   		<tr>
			<td class="Content_tab_style1" nowrap>编制日期：</td>
			<td class="Content_tab_style2">
				<fmt:formatDate value="${requiredCollect.writeDate}" type="both" dateStyle="long" pattern="yyyy-MM-dd" /> 
				<input type="hidden" id="writeDate" name="requiredCollect.writeDate" value="${requiredCollect.writeDate }"/>
			</td>
			<td class="Content_tab_style1">负责人单位：</td>
			<td class="Content_tab_style2">
				${deptName }
				<input type="hidden" name="requiredCollect.deptId" value="${requiredCollect.deptId }"/>
			</td>
			
		</tr>
		<tr>
			<td  class="Content_tab_style1"><span id="spanButtonPlaceHolder" ></span></td>
			<td class="Content_tab_style2" colspan="3">
				<!-- 附件存放 -->
				<div  id="fileDiv" class="panel"> 
				</div>
				<input class="cancel" id="btnCancel" name="cancelImg" type="button" style="display: none" value="取消" onclick="swfu.cancelQueue();"  />
				<div id="fsUploadProgress" style="padding-left:200px;width: 200px;"></div>
				
			</td>
		</tr>
	</table>
	<table align="center" class="table_ys1" id="listtable">	
		
		<tr id="tdNum" align="center" class="Content_tab_style_04">
			<th width="5%" nowrap >操作 <img src="images/select.gif" onclick="selectRequiredPlan();" title="选择需求计划"/></th>
			<th width="95px" nowrap>编码<font color="#ff0000">*</font></th>
			<th width="10%" nowrap>名称 </th>
			<th width="10%" nowrap>规格型号 </th>
			<th width="10%" nowrap>计量单位</th>
			<th width="55px" nowrap>数量<font color="#ff0000">*</font></th>
			<th width="100px" nowrap>交货时间</th>
			<th width="20%" nowrap>备注</th>
		</tr>
		<c:forEach items="${listValue}" var="requiredCollectDetail" varStatus="status">
			<tr  class="input_ys1">
				<td><input type="hidden" name='rcdList[${status.index}].rmdId' value="${requiredCollectDetail.rmdId}"/>
				    <button class='btn btn-mini btn-danger' type="button"  onclick='deleteRow(this,${requiredCollectDetail.rmdId})'><i class="icon-white icon-trash"></i></button>
				</td>
				<td>
				    ${requiredCollectDetail.materialType}<input type='hidden' name='rcdList[${status.index}].buyCode' readonly value='${requiredCollectDetail.buyCode}' size='10' style="width: 95px" onclick='selectMaterial(${status.index})' />
				</td>
				<td>
				   ${requiredCollectDetail.buyName}<input type='hidden' value='${requiredCollectDetail.buyName}' name='rcdList[${status.index}].buyName' /> 
				</td>
				<td>
				   ${requiredCollectDetail.materialType}<input type='hidden'  value='${requiredCollectDetail.materialType}' name='rcdList[${status.index}].materialType' />
				</td>
				<td>
				   ${requiredCollectDetail.unit}<input type='hidden'  value='${requiredCollectDetail.unit}' name='rcdList[${status.index}].unit' />
			    </td>
			    <td>
			       <input type='text' name='rcdList[${status.index}].amount' style='width:55px;'  id='amount_${status.index}' value='${requiredCollectDetail.amount}'  size='5' onblur='checkAmount(${requiredCollectDetail.amount},this)' />
			    </td>
				<td>
					<fmt:formatDate value="${requiredCollectDetail.deliverDate}" type="both" dateStyle="long" pattern="yyyy-MM-dd" /><input type='hidden' name='rcdList[${status.index}].deliverDate'  value='<fmt:formatDate value="${requiredCollectDetail.deliverDate}" type="both" dateStyle="long" pattern="yyyy-MM-dd" />' />
		        </td>
				<td><input type="text" name='rcdList[${status.index}].remark'  value="${requiredCollectDetail.remark }" style="width: 90%"/></td>
			</tr>
		</c:forEach>		
	</table>
	
	<div class="buttonDiv">
		<button class="btn btn-success" id="btn-save" ><i class="icon-white icon-ok-sign"></i>保存</button>
		<button class="btn btn-cacel" type="button" id="btn-cacel"  onclick="javascript:history.go(-1);" ><i class="icon icon-repeat"></i>返回</button>
	 </div>	
</form>
</div>
</div>
</div>
<script type="text/javascript">
$(function(){
	var defaultForm=$(".defaultForm").Validform({
		btnSubmit:"#btn-save", 
		tiptype:function(msg,o,cssctl){
			if(!o.obj.is("form")){//验证表单元素时o.obj为该表单元素，全部验证通过提交表单时o.obj为该表单对象;
				var objtip=o.obj.parents("td").find(".Validform_checktip");
				cssctl(objtip,o.type);
				objtip.text(msg);
				
				var infoObj=o.obj.parents("td").find(".info");
				if(o.type==2){
					infoObj.fadeOut(200);
				}else{
					if(infoObj.is(":visible")){return;}
					var left=o.obj.offset().left,
						top=o.obj.offset().top;
	
					infoObj.css({
						left:left+10,
						top:top-45
					}).show().animate({
						top:top-35	
					},200);
				}
				
			}	
		}
	});
})
</script>	
</body>
</html>